<?php 
class user_admin 
{ 
	function admin_user_list() 
	{ 
		global $mysql_conn,$v_file;
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `user` limit ".$list_limit;
		} else {
			$sql = "SELECT * from `user` WHERE `user_name` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$user_id = $row['user_id'];
			$user_name = $row['user_name'];
			$user_password = $row['user_password'];
			$user_type = $row['user_type'];
			$user_type_time_end = $row['user_type_time_end'];
			$user_bot_num = $row['user_bot_num'];
			$user_glod = $row['user_glod'];
			$sql_type = "SELECT * from `user_type` WHERE `type_id` = '".$user_type."'";
			$result_type = mysql_query($sql_type,$mysql_conn);
			@$row_type=mysql_fetch_array($result_type);
			$user_type_name = $row_type['type_name'];
			$userlist .= "<tr><td>";
			$userlist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$userlist .= "</td>";
			$userlist .= "<td>".$user_id."</td>";
			$userlist .= "<td>".$user_name."</td>";
			$userlist .= "<td>".$user_password."</td>";
			$userlist .= "<td>".$user_type_name."</td>";
			$userlist .= "<td>".$user_bot_num."</td>";
			$userlist .= "<td>".$user_type_time_end."</td>";
			$userlist .= "<td>".$user_glod."</td>";
			$userlist .= "<td>";
			$userlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_user_view(".$user_id.");'><i class='fa fa-file-text-o'></i> 详细 </a>";
			$userlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_user_edit(".$user_id.");'><i class='fa fa-edit'></i> 编辑 </a>";
			$userlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_user_del(".$user_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$userlist .= "</td></tr>";
		}
		require($v_file);
	}
	function admin_user_add() 
	{ 
		global $mysql_conn,$v_file;
		require($v_file);
	}
	function admin_user_add_do() 
	{ 
		global $mysql_conn;
		$user_name = $_POST['user_name'];
		$user_password = $_POST['user_password'];
		$sql = "SELECT * from `user` WHERE `user_name` = '".$user_name."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql="INSERT INTO user (user_id, user_name, user_password, user_type) VALUES (NULL,'$user_name','$user_password',6)";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$sql = "SELECT * from `user` WHERE `user_name` = '".$user_name."'";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			$user_id = $row['user_id'];
			$sql="INSERT INTO user_info (info_id) VALUES ($user_id)";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//用户注册成功
		} else {
			echo  "1";//用户已存在
		}
	}
	function admin_user_view() 
	{ 
		global $mysql_conn,$v_file;
		$user_id = $_GET['user_id'];
		$sql = "SELECT * from `user_info` WHERE `info_id` = '".$user_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$name = $row['name'];
		$sex = $row['sex'];
		$birthday = $row['birthday'];
		$address = $row['address'];
		$telphone = $row['telphone'];
		$tel = $row['tel'];
		$qq = $row['qq'];
		$wechat = $row['wechat'];
		$alipay = $row['alipay'];
		$email = $row['email'];
		$questions1 = $row['questions1'];
		$questions2 = $row['questions2'];
		$questions3 = $row['questions3'];
		$answer1 = $row['answer1'];
		$answer2 = $row['answer2'];
		$answer3 = $row['answer3'];
		require($v_file);
	}
	function admin_user_view_do() 
	{ 
		global $mysql_conn;
		$user_id = $_POST['user_id'];
		$name = $_POST['name'];
		$sex = $_POST['sex'];
		$birthday = $_POST['birthday'];
		$address = $_POST['address'];
		$telphone = $_POST['telphone'];
		$tel = $_POST['tel'];
		$qq = $_POST['qq'];
		$wechat = $_POST['wechat'];
		$alipay = $_POST['alipay'];
		$email = $_POST['email'];
		$questions1 = $_POST['questions1'];
		$questions2 = $_POST['questions2'];
		$questions3 = $_POST['questions3'];
		$answer1 = $_POST['answer1'];
		$answer2 = $_POST['answer2'];
		$answer3 = $_POST['answer3'];
		$sql = "UPDATE `user_info` SET `name` = '".$name."', `sex` = '".$sex."', `birthday` = '".$birthday."', `address` = '".$address."', `telphone` = '".$telphone."', `tel` = '".$tel."'
			, `qq` = '".$qq."', `wechat` = '".$wechat."', `alipay` = '".$alipay."', `email` = '".$email."', `questions1` = '".$questions1."'
			, `questions2` = '".$questions2."', `questions3` = '".$questions3."', `answer1` = '".$answer1."', `answer2` = '".$answer2."', `answer3` = '".$answer3."' WHERE `info_id` =".$user_id.";";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_user_edit() 
	{ 
		global $mysql_conn,$v_file;
		$user_id = $_GET['user_id'];
		$sql = "SELECT * from `user` WHERE `user_id` = '".$user_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$user_type = $row['user_type'];
		$user_password = $row['user_password'];
		$user_type_time_end = $row['user_type_time_end'];
		$user_bot_num = $row['user_bot_num'];
		$user_glod = $row['user_glod'];
		$sql = "SELECT * from `user_type`";
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$type_id = $row['type_id'];
			$type_name = $row['type_name'];
			if ($type_id == $user_type) {
				$typelist .= "<option value='".$type_id."' selected>".$type_name."</option>";
			} else {
				$typelist .= "<option value='".$type_id."'>".$type_name."</option>";
			}
		}
		require($v_file);
	}
	function admin_user_edit_do() 
	{ 
		global $mysql_conn;
		$user_id = $_POST['user_id'];
		$user_type = $_POST['user_type'];
		$user_password = $_POST['user_password'];
		$user_type_time_end = $_POST['user_type_time_end'];
		$user_bot_num = $_POST['user_bot_num'];
		$user_glod = $_POST['user_glod'];
		$sql = "UPDATE `user` SET `user_type` = '".$user_type."', `user_password` = '".$user_password."', `user_type_time_end` = '".$user_type_time_end."', `user_bot_num` = '".$user_bot_num."', `user_glod` = '".$user_glod."' WHERE `user_id` ='".$user_id."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_user_del_do() 
	{ 
		global $mysql_conn;
		$user_id = $_POST['user_id'];
		$sql = "DELETE from `user` WHERE `user_id` = '".$user_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$sql = "DELETE from `user_info` WHERE `info_id` = '".$user_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
} 
/* End of file democontroller.php */ 